﻿/*-------------------------------------------------------------------------
* 命名空间: MyToDo.ViewModels/SkinViewModel
* 类       名: SkinViewModel
* 功      能:  TD
* 时      间:  2023/12/18 15:34:17
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using MaterialDesignColors;
using MaterialDesignColors.ColorManipulation;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace MyToDo.ViewModels
{
    public class SkinViewModel : BindableBase
    {
        public SkinViewModel(PaletteHelper PaletteHelper)
        {
            ChangeHueCommand = new DelegateCommand<object>(DoChangeHueCommand);
            _paletteHelper = PaletteHelper;
            IsDarkTheme = true;
        }

        private bool isDarkTheme;

        public bool IsDarkTheme
        {
            get { return isDarkTheme; }
            set
            {
                isDarkTheme = value;
                RaisePropertyChanged();
                ModifyTheme(value ? Theme.Dark : Theme.Light);
            }
        }

        private void ModifyTheme(IBaseTheme ThemeColor)
        {
            var theme = _paletteHelper.GetTheme();
            theme.SetBaseTheme(ThemeColor);
            _paletteHelper.SetTheme(theme);
        }

        public IEnumerable<ISwatch> Swatches { get; } = SwatchHelper.Swatches;

        private void DoChangeHueCommand(object HueObj)
        {
            var hue = (Color)HueObj;
            ITheme theme = _paletteHelper.GetTheme();
            theme.PrimaryLight = new ColorPair(hue.Lighten());
            theme.PrimaryMid = new ColorPair(hue);
            theme.PrimaryDark = new ColorPair(hue.Darken());
            _paletteHelper.SetTheme(theme);

        }

        public DelegateCommand<object> ChangeHueCommand { get; private set; }

        private readonly PaletteHelper _paletteHelper;
    }
}
